#!/bin/sh

# 获取所有暂存的go文件
STAGED_GO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$')

if [ -z "$STAGED_GO_FILES" ]; then
    exit 0
fi

echo "Running golangci-lint on staged files..."
golangci-lint run --new-from-rev=HEAD~ $STAGED_GO_FILES

if [ $? -ne 0 ]; then
    echo "golangci-lint found issues in staged files"
    exit 1
fi

gofmt -w .
git add -u

# 只对修改的文件运行特定linter
golangci-lint run -v --fast -E gofmt -E govet -E staticcheck
